﻿using System.Linq;
using UniMana.Data;
using UniMana.Utils.Configs;
using UniMana.Utils.Controls;

namespace UniMana.Data
{
    public class Personnel_Personnel_SubjectInfo
    {
        private DBMain m_data = new DBMain();
        public bds m_bds = new bds();
        public void Save()
        {
            m_data.m_DCSave.SubmitChanges();
        }
        public void Delete()
        {
            m_bds.DeleteCurrent();
            m_data.m_DCSave.SubmitChanges();
        }

        public Personnel_Personnel_Subject Properties
        {
            get { return m_bds.Current as Personnel_Personnel_Subject; }
        }

        public Personnel_Personnel_SubjectInfo(string m_strPersonKey = DefaultConfig.EMPTY_GUID, int m_iSubjectKey = -1)
        {
            var IQuery = m_data.m_DCSave.Personnel_Personnel_Subjects.Where(tb => tb.Personnel_PersonnelKey.ToString() == m_strPersonKey && tb.Training_SubjectKey == m_iSubjectKey);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Personnel_Personnel_Subject();
                m_bds.Add(Row);
            }
        }

    }
}
